package Smallprogram.dao.impl;

import Smallprogram.dao.BaseDao;
import Smallprogram.dao.Usersdao;
import Smallprogram.entiy.Users;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class UsersDaoImpl extends BaseDao implements Usersdao {
    @Override
    public List<Users> selectusers() {
        String sql="select * from Usersname";
        ResultSet res =this.executeQuery(sql);
        List<Users> list =new ArrayList<>();
        try {
            while (res.next()){
                list.add(new Users(res.getInt(1), res.getString(2),res.getString(3),res.getString(4),res.getString(5),res.getDouble(6),res.getString(7),res.getInt(8)));
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return list;
    }

    @Override
    public int updateysers(Users users) {
        String sql="UPDATE `BurgerKingDB`.`Usersname` SET `balance` =?,`userpoints`=? WHERE `usersid` = ?;";
        return this.executeUpdate(sql,users.getBalance(),users.getUserpoints(),users.getUsersid());
    }

    @Override
    public double selectbalance() {
        String sql="select balance from Usersname";
        ResultSet res=this.executeQuery(sql);
        double ind=0.00;
        try {
            while (res.next()){
                ind=res.getDouble(1);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return ind;
    }

    @Override
    public int selectuserpoints() {

        String sql="select userpoints from Usersname";
        ResultSet res=this.executeQuery(sql);
        int ind=0;
        try {
            while (res.next()){
                ind=res.getInt(1);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return ind;

    }
}
